//
//  myTabBarViewController.m
//  CustomTabBar
//
//  Created by giantumbrella on 15/5/20.
//  Copyright (c) 2015年 zhaojuan. All rights reserved.
//

#import "myTabBarViewController.h"
#import "TrialViewController.h"
#import "SurveyViewController.h"
#import "BuyViewController.h"
#import "MeViewController.h"
#import "HomeViewController.h"

#import "SubmitOrderVC.h"
#import "AddNewAddressVC.h"
@interface myTabBarViewController ()

@end

@implementation myTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
     self.view.backgroundColor = [UIColor whiteColor];
    [self setupAllChildViewControllers];
    [self logSucess];
}

- (void)logSucess
{
     self.selectedIndex = 2;
}

-(void)setupAllChildViewControllers{
    //1.试用
    TrialViewController *trialView = [[TrialViewController alloc] init];
    [self setupChildViewController:trialView title:@"试用" imageName:@"试用" selectedImageName:@"试用-选中"];
    //2.购买
//    BuyViewController *establishView = [[BuyViewController alloc]init];
//    [self setupChildViewController:establishView title:@"特卖" imageName:@"特卖" selectedImageName:@"特卖-选中"];
//    SubmitOrderVC *establishView = [[SubmitOrderVC alloc]init];
//    [self setupChildViewController:establishView title:@"特卖" imageName:@"特卖" selectedImageName:@"特卖-选中"];
    
    AddNewAddressVC *establishView = [[AddNewAddressVC alloc]init];
    [self setupChildViewController:establishView title:@"特卖" imageName:@"特卖" selectedImageName:@"特卖-选中"];
    //首页
    HomeViewController *homeView = [[HomeViewController alloc] init];
    [self setupChildViewController:homeView title:nil imageName:@"首页-70x70" selectedImageName:@"首页-70x70"];
    
    //3.调查
    SurveyViewController *surveyView = [[SurveyViewController alloc]init];
    [self setupChildViewController:surveyView title:@"调查" imageName:@"调查" selectedImageName:@"调查-选中"];
    
    //4.我
    MeViewController *meView = [[MeViewController alloc] init];
    [self setupChildViewController:meView title:@"我" imageName:@"个人中心" selectedImageName:@"个人中心-选中"];
}

//初始化一个子控件
- (void)setupChildViewController:(UIViewController *)childVC title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName
{

//1.设置控件属性
    
//    [[UITabBar appearance] setTintColor:[UIColor redColor]];
    childVC.title = title;
    if ([[[UIDevice currentDevice] systemVersion]floatValue] >= 7.0) {
    
        childVC.tabBarItem.image = [[UIImage imageNamed:imageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        childVC.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
    } else {
       
        //TBD
    }

    //2.包装一个导航栏
    UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:childVC];
    [self addChildViewController:navi];
}


@end
